/* EasyWay Game Engine
 * Copyright (C) 2006 Daniele Paggi.
 *  
 * Written by: 2006 Daniele Paggi<dshnt@hotmail.com>
 *   
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.easyway.objects.sprites2D;

import java.io.Serializable;
import java.util.ArrayList;

import org.easyway.annotations.editor.Creator;
import org.easyway.annotations.editor.Info;
import org.easyway.annotations.editor.UEditor;
import org.easyway.annotations.editor.X;
import org.easyway.annotations.editor.Y;
import org.easyway.interfaces.base.ITexture;
import org.easyway.interfaces.sprites.ISpriteColl;

/**
 * A simple sprite that can be used to tests the collisions.
 * 
 * @Author Daniele Paggi
 */
@UEditor//
public class SimpleSpriteColl extends SimpleSprite implements
		ISpriteColl,
		Serializable {

	/**
	 * generated version
	 */
	private static final long serialVersionUID = -573573212294334865L;

	/**
	 * a lists that contains the objects witch the object has done a collision.<br>
	 * example of use<br>
	 * public void onCollision() {<br>
	 * collisionList.startStacn(); <br>
	 * while( collisionList.hasElements() ) { <br>
	 * ISpriteColl sp = (ISpriteColl)collisionList.getCurrent();<br>
	 * ... } <br> } <br>
	 */
	public ArrayList<ISpriteColl> collisionList = new ArrayList<ISpriteColl>(6);

	/**
	 * indicates if the object is added or not to the auto-collisionLists.
	 */
	protected boolean collAdded = false;

	/**
	 * the collision mask
	 */
	private Mask mask;

	public SimpleSpriteColl() {
		super();
	}

	public SimpleSpriteColl(int layer) {
		super(layer);
	}

	public SimpleSpriteColl(float x, float y) {
		super(x, y);
	}

	@Creator("x, y, image")//
	public SimpleSpriteColl(@X @Info("x") float x, @Y @Info("y") float y,
			@Info("Image") ITexture img) {
		super(x, y, img);
	}

	public SimpleSpriteColl(float x, float y, int layer) {
		super(x, y, layer);
	}

	public SimpleSpriteColl(ITexture img) {
		super(img);
	}

	public SimpleSpriteColl(ITexture img, int layer) {
		super(img, layer);
	}

	public SimpleSpriteColl(boolean quad) {
		super(quad);
	}

	public SimpleSpriteColl(int layer, boolean quad) {
		super(layer, quad);
	}

	public SimpleSpriteColl(float x, float y, boolean quad) {
		super(x, y, quad);
	}

	@Creator("x, y, image, quad")//
	public SimpleSpriteColl(@X @Info("x") float x, @Y @Info("y") float y,
			@Info("image") ITexture img, @Info("use Quad") boolean quad) {
		super(x, y, img, quad);
	}

	public SimpleSpriteColl(float x, float y, int layer, boolean quad) {
		super(x, y, layer, quad);
	}

	public SimpleSpriteColl(ITexture img, boolean quad) {
		super(img, quad);
	}

	public SimpleSpriteColl(ITexture img, int layer, boolean quad) {
		super(img, layer, quad);
	}

	public SimpleSpriteColl(float x, float y, ITexture img, int layer) {
		super(x, y, img, layer);
	}

	public SimpleSpriteColl(float x, float y, ITexture img, int layer,
			boolean quad) {
		super(x, y, img, layer, quad);
	}

	public SimpleSpriteColl(boolean autoAdd, float x, float y, int layer,
			int idLayer) {
		super(autoAdd, x, y, layer, idLayer);
	}

	public SimpleSpriteColl(boolean autoAdd, float x, float y, int layer) {
		super(autoAdd, x, y, layer);
	}

	public SimpleSpriteColl(boolean autoAdd, float x, float y, ITexture img,
			int layer, int idLayer) {
		super(autoAdd, x, y, img, layer, idLayer);
	}

	public SimpleSpriteColl(boolean autoAdd, float x, float y, ITexture img) {
		super(autoAdd, x, y, img);
	}

	public SimpleSpriteColl(boolean autoAdd, float x, float y) {
		super(autoAdd, x, y);
	}

	public SimpleSpriteColl(boolean autoAdd, int layer, int idLayer) {
		super(autoAdd, layer, idLayer);
	}

	public SimpleSpriteColl(boolean autoAdd, int layer) {
		super(autoAdd, layer);
	}

	public SimpleSpriteColl(boolean autoAdd, ITexture img, int layer) {
		super(autoAdd, img, layer);
	}

	public SimpleSpriteColl(boolean autoAdd, ITexture img) {
		super(autoAdd, img);
	}

	public SimpleSpriteColl(float x, float y, int layer, int idLayer) {
		super(x, y, layer, idLayer);
	}

	public SimpleSpriteColl(float x, float y, ITexture img, int layer,
			int idLayer) {
		super(x, y, img, layer, idLayer);
	}

	public SimpleSpriteColl(int layer, int idLayer) {
		super(layer, idLayer);
	}

	public SimpleSpriteColl(ITexture img, int layer, int idLayer) {
		super(img, layer, idLayer);
	}
	
	public SimpleSpriteColl(SimpleSpriteColl obj) {
		super(obj);
		mask = obj.mask;
	}

	// -------------------------------------------------------------------------

	/**
	 * sets a new CollisionMask
	 */
	public void setMask(Mask mask) {
		this.mask = mask;
	}

	public float getRotation2D() {
		return 0;
	}

	public Mask getMask() {
		if (mask != null)
			return mask;
		if (image != null)
			return image.getMask();
		org.easyway.utils.Utility.error("the sprite hasn't any mask",
			"Sprite.getMask()");
		return null;
	}

	public ArrayList<ISpriteColl> getCollisionList() {
		return collisionList;
	}

	public void onCollision() {
	}

	public boolean getAddedToCollisionList() {
		return collAdded;
	}

	public void setAddedToCollisionList(boolean value) {
		collAdded = value;
	}
	
	public Object clone() {
		return new SimpleSpriteColl(this);
	}

}
